<html>
    <head>
        <meta charset="utf-8">
        <title>地图缩放到指定的矩形范围</title>
        <!-- leaflet的css样式 -->
        <link rel="stylesheet" href="../lib/leaflet.css" />
        <!-- leaflet的js库 -->
        <script type="text/javascript" src="../lib/leaflet-src.js"></script>
        <!-- 地图容器样式 -->
        <style>
            #mapDiv{
                width: 100%;
                height: 100%;
            }
        </style>

        <script type="text/javascript">
            var map = null; 

            function init(){

                map = L.map("mapDiv", { 
                    center: [39.90,116.39],
                    zoom: 9,
                });

                L.tileLayer( 
                    'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
                ).addTo(map);
            }

            function onSetMaxBounds(){
                //定义地图显示的矩形范围
                map.setMaxBounds([
                        [39.368, 115.374],  //左下角点,
                        [41.127, 117.524]   //右上角点
                    ]);
            }

        </script>
            
    </head>
    <body onload="init()">
        <span>地图限制到北京范围</span><br>
        <span><input type="button" value="北京范围" onclick="onSetMaxBounds()"></span>
        <!--地图的容器-->
        <div id="mapDiv"></div>
    </body>
</html>



